More rows for one record

edited October 2013 in FastReport 4.0
Hello,

I have MyTable with two fields - Item and Number of pieces

Example :
Item1 - 5 pcs
Item2 - 1 pc
Item3 - 3 pcs
...

I want print for each record more rows (row count is equal as number of pieces).

Example :
Item1 - 5 pcs
Item1 - 5 pcs
Item1 - 5 pcs
Item1 - 5 pcs
Item1 - 5 pcs
Item2 - 1 pc
Item3 - 3 pcs
Item3 - 3 pcs
Item3 - 3 pcs
...

I solved it in this way :

var
ds: TfrxDataSet;
Count:integer;
IsFirst:boolean;

procedure DetailData1OnBeforePrint(Sender: TfrxComponent);
begin
if IsFirst then ds.Prior;
end;

procedure DetailData1OnAfterPrint(Sender: TfrxComponent);
begin
Inc(Count); IsFirst:=False;
if (Count < <MyTable."Pieces"> ) then begin
if ds.RecNo=0 then IsFirst:=True
else ds.Prior;
end else begin
Count:=0;
end;
end;

begin
ds := Report.GetDataset('MyTable');
Count:=0;
First:=False;
end.

It is working, but problem occurs if in MyTable is only one record. I think that problem is in function ds.Prior. If we are on first record and call ds.Prior, FastReport do not set it to BOF, but ignore it ...
Have you any ideas as solve it ?
Thanks !

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 4:29PM
    that is not the way i would habdle it
    i would create an unattached child band duplicating the memos of the mdband
    in the obp event of the master write code to populate the child memos if the number of pieces is>1
    set an index variable to number of pieces minus 1
    then in the oap event call the engine .showband(name of childband);
    in a while loop.
  • gordkgordk St.Catherines On. Canada.
    edited 4:29PM
    sorry i miss read your problem change my refrence to master data to detaildata.
  • gordkgordk St.Catherines On. Canada.
    edited 4:29PM
    an easier method is to use a subdetail band containg the detail memos you want.
    do not connect the band to a dataset, in the obp event of the detail data
    write code to set the visibility and rowcount prop of the subdetail band.
    ie
    if <MyTable."Pieces"> >1 then
    begin
    subdetail1.visible := true;
    subdetail1.rowcount := <MyTable."Pieces">-1;
    end
    else subdetail1.visible := false;
    end;
  • edited 4:29PM
    gordk wrote: »
    an easier method is to use a subdetail band containg the detail memos you want.
    do not connect the band to a dataset, in the obp event of the detail data
    write code to set the visibility and rowcount prop of the subdetail band.
    ie
    if <MyTable."Pieces"> >1 then
    begin
    subdetail1.visible := true;
    subdetail1.rowcount := <MyTable."Pieces">-1;
    end
    else subdetail1.visible := false;
    end;

    Thank you very much for good tip ! It is working.

    But I did it easier more - I keep DetailBand empty, all memos copy to SubdetailBand and into OnBeforePrint of DetailBand I put only :
    Subdetail1.rowcount := <MyTable."Pieces"> >

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.